function stop(id) {
    $.post("../api/stop", {
            id: id
        },
        function (data, status) {
            if (data != null && data.success) {
                $.gritter.add({
                    title: 'Success!',
                    text: '提交成功，请稍后刷新',
                    sticky: false,
                    time: 1500,
                    class_name: 'gritter-light,gritter-fontsize',
                    after_close: function (e) {
                        window.location.reload();
                    }
                });

            } else {
                $.gritter.add({
                    title: 'Fail!',
                    text: '执行失败：' + data.message,
                    sticky: false,
                    time: 3000,
                    after_close: function (e) {
                    }
                });
            }

        }
    );
}

function start(id) {
    $.post("../api/start", {
            id: id
        },
        function (data, status) {
            if (data !== null && data.success) {
                $.gritter.add({
                    title: 'Success!',
                    text: '提交成功，请稍后刷新',
                    sticky: false,
                    time: 1500,
                    class_name: 'gritter-fontsize',
                    after_close: function (e) {
                        window.location.reload();
                    }
                });
            } else {
                $.gritter.add({
                    title: 'Fail!',
                    text: '执行失败：' + data.message,
                    sticky: false,
                    time: 3000,
                    after_close: function (e) {
                    }
                });
            }
        }
    );
}


function deleteConfig(id) {
    if (confirm('确定要删除吗') == true) {
        $.post("../api/delete", {
                id: id
            },
            function (data, status) {
                if (data != null && data.success) {
                    window.location.reload();
                } else {
                    $.gritter.add({
                        title: 'Fail!',
                        text: '执行失败：' + data.message,
                        sticky: false,
                        time: 3000,
                        after_close: function (e) {
                        }
                    });
                }
            }
        );

    } else {
        return false;
    }
}

function copyConfig(id) {
    $.post("../api/copyConfig", {
            id: id,
        },
        function (data, status) {
            if (data != null && data.success) {
                $.gritter.add({
                    title: 'Success!',
                    text: '复制成功',
                    sticky: false,
                    time: 1500,
                    class_name: 'gritter-fontsize',
                    after_close: function (e) {
                        window.location.reload();
                    }
                });
                return true;
            }

            alert("复制失败：" + data.message);
        }
    );
}

function updateStatus(id) {
    $.post("../api/azKaBanSql/updateStatus", {
            id: id
        },
        function (data, status) {
            if (data != null && data.success) {
                $.gritter.add({
                    title: 'Success!',
                    text: '执行成功',
                    sticky: false,
                    time: 1500,
                    class_name: 'gritter-fontsize',
                    after_close: function (e) {
                        window.location.reload();
                    }
                });

            } else {
                $.gritter.add({
                    title: 'Fail!',
                    text: '执行失败：' + data.message,
                    sticky: false,
                    time: 3000,
                    after_close: function (e) {
                    }
                });
            }

        }
    );
}


function openConfig(id) {
    $.post("../api/open", {
            id: id
        },
        function (data, status) {
            if (data != null && data.success) {
                $.gritter.add({
                    title: 'Success!',
                    text: '执行成功',
                    sticky: false,
                    time: 1500,
                    class_name: 'gritter-fontsize',
                    after_close: function (e) {
                        window.location.reload();
                    }
                });

            } else {
                $.gritter.add({
                    title: 'Fail!',
                    text: '执行失败：' + data.message,
                    sticky: false,
                    time: 3000,
                    after_close: function (e) {
                    }
                });
            }

        }
    );
}


function closeConfig(id) {
    $.post("../api/close", {
            id: id
        },
        function (data, status) {
            if (data != null && data.success) {
                $.gritter.add({
                    title: 'Success!',
                    text: '执行成功',
                    sticky: false,
                    time: 1500,
                    class_name: 'gritter-fontsize',
                    after_close: function (e) {
                        window.location.reload();
                    }
                });
            } else {
                $.gritter.add({
                    title: 'Fail!',
                    text: '执行失败：' + data.message,
                    sticky: false,
                    time: 1500,
                    after_close: function (e) {
                    }
                });
            }

        }
    );
}

function savePoint(id) {
    if (confirm('确定要手执行savePoint吗？') == true) {
        $.post("../api/savepoint", {
                id: id
            },
            function (data, status) {
                if (data != null && data.success) {
                    $.gritter.add({
                        title: 'Success!',
                        text: '执行成功，请稍后刷新',
                        sticky: false,
                        time: 1500,
                        class_name: 'gritter-light,gritter-fontsize',
                        after_close: function (e) {
                            window.location.reload();
                        }
                    });
                } else {
                    $.gritter.add({
                        title: 'Fail!',
                        text: '执行失败：' + data.message,
                        sticky: false,
                        time: 3000,
                        after_close: function (e) {
                        }
                    });
                }
            }
        );
    } else {
        return false;
    }
}

function searchForm(pageNum) {
    $("#pageNum").attr("value", pageNum);
    $("form[name='search']").submit();

}

function refreshForm() {
    $("form[name='search']").submit();

}

function executeFlowShow(id) {
    $("#BASE_BOUNCED").show();
    // 把id写入到隐藏框
    $('#id').val(id);

};


function gritter_success(text) {
    $.gritter.add({
        title: 'Success!',
        text: text,
        sticky: false,
        time: 1500,
        class_name: 'gritter-light,gritter-fontsize'
    });
}

function executeFlow() {
    if (confirm('确定要手执行吗？') == true) {
        $.post("../api/azKaBanSql/runSql", {
                id: $('#id').val(),
                extParas: $('#extParas').val(),
                indicatorCycle: $('#indicatorCycle').val(),
                startTime: $('#startTime').val(),
                endTime: $('#endTime').val()
            }, function (data, status) {
                if (data != null && data.success) {
                    // 弹出提示
                    gritter_success('执行成功，请查看日志');

                    // 当前层关闭
                    $("#BASE_BOUNCED").hide();

                    // 开始展示调用日志接口
                    socketFlowLogs(data)

                } else {
                    $.gritter.add({
                        title: 'Fail!',
                        text: '执行失败：' + data.message,
                        sticky: false,
                        time: 3000,
                        after_close: function (e) {
                        }
                    });
                }
            }
        );
    } else {
        return false;
    }
};

function hidder() {
    $("#BASE_BOUNCED").hide();
}




